Imports System.Collections.ObjectModel
Imports PTIC_Util
Imports PTIC_GestionBDD
Imports OMANE.Common.Model.Interfaces
Imports Actuariat


Public Class TableMortaliteFromDataTable
    Implements ITableMortalite

    Public Sub New(ByVal Dtble As DataTable, ByVal Nom As String)
        m_Nom = Nom
        m_DTble = Dtble
        ReDim m_Values(Dtble.Rows.Count - 1, 1)
        Dim i As Integer = 0
        For Each Row As DataRow In Dtble.Rows
            m_Values(i, 0) = i
            m_Values(i, 1) = Row(nomTxMortAn)
            i = i + 1
        Next
    End Sub

    Public Function AgeAnMinFromQxAn(ByVal QxAn As Double) As Integer Implements Actuariat.ITableMortalite.AgeAnMinFromQxAn
        Dim result As Integer, ecart_min As Double = Double.PositiveInfinity
        For i As Integer = 0 To m_Values.GetUpperBound(0)
            If m_Values(i, 1) < QxAn And Math.Abs(m_Values(i, 1) - QxAn) < ecart_min Then
                result = m_Values(i, 0)
                ecart_min = Math.Abs(m_Values(i, 1) - QxAn)
            End If
        Next
        Return result
    End Function

    Private m_Values(,) As Double
    Public ReadOnly Property Values As Double(,) Implements Actuariat.ITableMortalite.Values
        Get
            Return m_Values
        End Get
    End Property

    Private m_Nom As String
    Public ReadOnly Property Nom As String Implements Actuariat.ITableTravail.Nom
        Get
            Return m_Nom
        End Get
    End Property

    Private m_DTble As DataTable
    Public ReadOnly Property DataTable As System.Data.DataTable Implements Actuariat.ITableMortalite.DataTable
        Get
            Return m_DTble
        End Get
    End Property

    Public ReadOnly Property TxMortalite(ByVal age As Integer) As Object Implements Actuariat.ITableMortalite.TxMortalite
        Get
            Return m_Values(age, 1)
        End Get
    End Property
End Class